package com.tr.listView;

import com.tr.date_8_listview.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;

public class TwoItemActivity extends Activity{
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mainactivity);
		ListView lv=(ListView) findViewById(R.id.listView);
		lv.setAdapter(new TwoItemAdapter());
	}
	
	class TwoItemAdapter extends BaseAdapter{
		
		@Override
		public int getItemViewType(int position) {
			if(position%2==0)
				return 0;
			else
				return 1;
		}
		
		@Override
		public int getViewTypeCount() {
			return 2;
		}
		@Override
		public int getCount() {
			return 100;
		}

		@Override
		public Object getItem(int position) {
			return null;
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			int type=this.getItemViewType(position);
			if(type==0)
				return LayoutInflater.from(TwoItemActivity.this).inflate(R.layout.item1, null);
			else if(type==1)
				return LayoutInflater.from(TwoItemActivity.this).inflate(R.layout.item2, null);
			else
				return null;
		}
		
	}
}






